﻿package com.jxl.dnd.spells
{
	import flash.events.EventDispatcher;
	
	public class Spell extends EventDispatcher
	{
		
		static var SCHOOL_ABJURATION:Number = 0;
		static var SCHOOL_CONJURATION:Number = 1;
		static var SCHOOL_DIVINATION:Number = 2;
		static var SCHOOL_ENCHANTMENT:Number = 3;
		static var SCHOOL_EVOCATION:Number = 4;
		static var SCHOOL_ILLUSION:Number = 5;
		static var SCHOOL_NECROMANCY:Number = 6;
		static var SCHOOL_TRANSMUTATION:Number = 7;
		static var SCHOOL_UNIVERSAL:Number = 8;
		
		static var CASTER_WIZARD:Number = 0;
		static var CASTER_SORCERER:Number = 1;
		static var CASTER_BARD:Number = 2;
		static var CASTER_PALADIN:Number = 3;
		static var CASTER_RANGER:Number = 4;
		
		static var RANGE_SMALL:Number = 0;
		static var RANGE_MEDIUM:Number = 1;
		static var RANGE_LARGE:Number = 2;
		
		static var COMPONENT_VERBAL:Number = 0;
		static var COMPONENT_SOMATIC:Number = 1;
		static var COMPONENT_MATERIAL:Number = 2;
		static var COMPONENT_FOCUS:Number = 3;
		static var COMPONENT_DIVINE_FOCUS:Number = 4;
		static var COMOPNENT_XP_COST:Number = 5;
		
		static var TYPE_ARCANE:Number = 0;
		static var TYPE_DIVINE:Number = 1;
		static var TYPE_SPECIAL_ABILITY:Number = 2;
		
		static var LEVEL_CANTRIP:Number = 0;
		static var LEVEL_FIRST:Number = 1;
		static var LEVEL_SECOND:Number = 2;
		static var LEVEL_THIRD:Number = 3;
		static var LEVEL_FOURTH:Number = 4;
		static var LEVEL_FIFTH:Number = 5;
		static var LEVEL_SIXTH:Number = 6;
		static var LEVEL_SEVENTH:Number = 7;
		static var LEVEL_EIGHTH:Number = 8;
		static var LEVEL_NINTH:Number = 9;
		static var LEVEL_TENTH:Number = 10;
		
		static var SPELL_ID:Number = -1;
		public var ID:Number;
		
		private var _name:String;
		private var _school:Number;
		private var _subSchool:Number;
		private var _castingTime:Number;
		private var _rangeSize:Number;
		private var _baseRange:Number;
		private var _rangePerLevel:Number;
		private var _effect:String;
		private var _baseDuration:Number;
		private var _durationPerLevel:Number;
		private var _savingThrow:Boolean;
		private var _spellResistance:Boolean;
		private var _description:String;
		private var _type:Number;
		private var _image:String;
		private var _spellEffect:SpellEffect;
		
		public var selected:Boolean;
		
		private var levels_obj:Object;
		private var components_obj:Object;
		
		public function get name():String
		{
			return _name;
		}
		
		public function set name(val:String):Void
		{
			_name = val;
			modelChanged();
		}
		
		public function get school():Number
		{
			return _school;
		}
		
		public function set school(val:Number):Void
		{
			_school = val;
			modelChanged();
		}
		
		public function get subSchool():Number
		{
			return _subSchool;
		}
		
		public function set subSchool(val:Number):Void
		{
			_subSchool = val;
			modelChanged();
		}
		
		public function get castingTime():Number
		{
			return _castingTime;
		}
		
		public function set castingTime(val:Number):Void
		{
			_castingTime = val;
			modelChanged();
		}
		
		public function get rangeSize():Number
		{
			return _rangeSize;
		}
		
		public function set rangeSize(val:Number):Void
		{
			_rangeSize = val;
			modelChanged();
		}
		
		public function get baseRange():Number
		{
			return _baseRange;
		}
		
		public function set baseRange(val:Number):Void
		{
			_baseRange = val;
			modelChanged();
		}
		
		public function get rangePerLevel():Number
		{
			return _rangePerLevel;
		}
		
		public function set rangePerLevel(val:Number):Void
		{
			_rangePerLevel = val;
			modelChanged();
		}
		
		public function get effect():String
		{
			return _effect;
		}
		
		public function set effect(val:String):Void
		{
			_effect = val;
			modelChanged();
		}
		
		public function get baseDuration():Number
		{
			return _baseDuration;
		}
		
		public function set baseDuration(val:Number):Void
		{
			_baseDuration = val;
			modelChanged();
		}
		
		public function get durationPerLevel():Number
		{
			return _durationPerLevel;
		}
		
		public function set durationPerLevel(val:Number):Void
		{
			_durationPerLevel = val;
			modelChanged();
		}
		
		public function get savingThrow():Boolean
		{
			return _savingThrow;
		}
		
		public function set savingThrow(val:Boolean):Void
		{
			_savingThrow = val;
			modelChanged();
		}
		
		public function get spellResistance():Boolean
		{
			return _spellResistance;
		}
		
		public function set spellResistance(val:Boolean):Void
		{
			_spellResistance = val;
			modelChanged();
		}
		
		public function get description():String
		{
			return _description;
		}
		
		public function set description(val:String):Void
		{
			_description = val;
			modelChanged();
		}
		
		public function get type():Number
		{
			return _type;
		}
		
		public function set type(val:Number):Void
		{
			_type = val;
			modelChanged();
		}
		
		public function get image():String
		{
			return _image;
		}
		
		public function set image(val:String):Void
		{
			_image = val;
			modelChanged();
		}
		
		public function get spellEffect():SpellEffect
		{
			return _spellEffect;
		}
		
		public function set spellEffect(val:SpellEffect):Void
		{
			_spellEffect = val;
			modelChanged();
		}
		
		// -----------------------------------------------------------
		// -----------------------------------------------------------
		
		public function Spell():void
		{
			Spell.SPELL_ID++;
			ID = Spell.SPELL_ID;
			
			levels_obj = {};
			components_obj = {};
			selected = false;
			modelChanged();
		}
		
		public function addLevel(casterType:Number, level:Number):Void
		{
			levels_obj[casterType] = level;
			modelChanged();
		}
		
		public function getLevel(casterType:Number):Number
		{
			return levels_obj[casterType];
		}
		
		public function addComponent(componentType:Number, desc:Object):Void
		{
			components_obj[componentType] = desc;
			modelChanged();
		}
		
		public function getComponent(componentType:Number):Object
		{
			return components_obj[componentType];
		}
		
		public function modelChanged(Void):Void
		{
			dispatchEvent({type: "modelChanged", target: this});
		}
	}
}